package de.bmuskalla.brainfuck.ui.editor.editors;

import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.editors.text.IEncodingSupport;
import org.eclipse.ui.editors.text.TextEditor;

import de.bmuskalla.brainfuck.ui.editor.breakpoints.BFLineBreakpointAdapter;

public class BFEditor extends TextEditor {

	private BFColorManager colorManager;

	public BFEditor() {
		super();
		colorManager = new BFColorManager();
		setSourceViewerConfiguration(new BFConfiguration(colorManager));
		setDocumentProvider(new BFDocumentProvider());
	}

	public void dispose() {
		colorManager.dispose();
		super.dispose();
	}

	public Object getAdapter(Class adapter) {
		if (IToggleBreakpointsTarget.class.equals(adapter))
			return new BFLineBreakpointAdapter();
		return super.getAdapter(adapter);
	}
	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ui.editors.text.TextEditor#doSetInput(org.eclipse.ui.IEditorInput)
	 */
	protected void doSetInput(IEditorInput input) throws CoreException {
		// transform editor input
		if (input instanceof IFileEditorInput) {
			IFile file = ((IFileEditorInput) input).getFile();
			input = new BFEditorInput(file);
		}
		super.doSetInput(input);
	}
}
